package com.titar.robot.ui.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.titar.robot.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


/**
 * Created by window on 2017/6/15.
 */

public class TipDialog extends CustomDialog implements View.OnClickListener {

    private TextView mTvContent;
    private TextView mBtnOK;
    private View.OnClickListener mPositiveClickListener;
    String contentTex;

    public static TipDialog show(Context context, String contentTex, @Nullable View.OnClickListener listener) {
        TipDialog dialog = new TipDialog(context);
        dialog.setContent(contentTex);
        dialog.setPositiveButton(listener);
        dialog.show();
        return dialog;
    }

    private TipDialog(@NonNull Context context) {
        super(context, R.layout.dialog_tip);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        setCanceledOnTouchOutside(false);
    }

    private void initView() {
        mTvContent = (TextView) findViewById(R.id.tv_content);
        mBtnOK = (TextView) findViewById(R.id.btn_ok);

        mTvContent.setText(contentTex);

        mBtnOK.setOnClickListener(this);
    }

    public TipDialog setContent(String text) {
        contentTex = text;
        return this;
    }

    public TipDialog setPositiveButton(View.OnClickListener listener) {
        mPositiveClickListener = listener;
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_ok:
                if (mPositiveClickListener != null) {
                    mPositiveClickListener.onClick(v);
                }
                break;
        }
        dismiss();
    }
}
